#ifndef MANAGEDIALOG_H
#define MANAGEDIALOG_H

#include <QDialog>
#include <QStringListModel>

#include "common.h"
#include "ServerManager.h"

class Configuration;
class QModelIndex;
class QUrl;

namespace Ui {
class ManageDialog;
}

class ManageDialog : public QDialog
{
    Q_OBJECT
    
public:
    explicit ManageDialog( Configuration *configuration, const ServerList *servers, QWidget *parent = NULL );
    ~ManageDialog();

signals:
    /**
     * @brief Will be emitted if creation of a server is requested.
     * @param QString The name.
     * @param QUrl The url.
     */
    void createServer( QString, QUrl );

    /**
     * @brief Will be emitted if deletion of a server is requested.
     * @param int The id.
     */
    void deleteServer( int );

    /**
     * @brief Will be emitted if editing of a server is requested.
     * @param int The id.
     * @param ServerSettings The new settings.
     */
    void editServer( int, ServerManager::ServerSettings );
    
private slots:
    /**
     * @brief Delete a server.
     */
    void deleteServer();

    /**
     * @brief Create a new server.
     */
    void newServer();

    /**
     * @brief Open file dialog for selection of sound file.
     */
    void openSoundFile();

    /**
     * @brief Save settings.
     */
    void save();

    /**
     * @brief Save a server.
     */
    void saveServer();

    /**
     * @brief Click on server in list.
     * @param index The model index of the server.
     */
    void serverClicked( const QModelIndex &index );

private:
    Ui::ManageDialog *ui;

    Configuration *mConfiguration;
    QStringListModel mModel;
    const ServerList *mServers;

    /**
     * @brief Show current server list.
     */
    void refreshServerList();
};

#endif // MANAGEDIALOG_H
